<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>报价单</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/list.css">
    <c:set value="<%=ResourcesUtil.getConfig(\"outbound_status_all\")%>" var="inventoryStatusAll" />
    <script>
    $(document).ready(function(){
    	
    });
  //获取 iframe 数量 
	var frLength = window.parent.frames.length;
	//父画面下标 
	var parentIndex = frLength-2;
    function saveQuantity() {
 		var inventoryDetailId = "${materialOutInbound.inventoryDetailId}";
 		var materialId = "${materialOutInbound.materialId}";
 		var length = $("input.inputQuantity").length;
 		var result = parseFloat(0);
 		var outResult = parseFloat(0);
 		for (var i = 0; i < length; i++) {
 			var materialQuantity = $(".materialQuantity")[i].innerHTML;
 			if (materialQuantity==null||materialQuantity=="") {
 				materialQuantity = "0";
			}
 			materialQuantity = materialQuantity.replace(/,/g,"");
 			result += parseFloat(materialQuantity);
		}
 		for (var i = 0; i < length; i++) {
 			var inputQuantity = $(".inputQuantity")[i].value;
 			if (inputQuantity==null||inputQuantity=="") {
 				inputQuantity = "0";
			}
 			inputQuantity = inputQuantity.replace(/,/g,"");
 			outResult += parseFloat(inputQuantity);
		}
 		var params = {"inventoryDetailId":inventoryDetailId,"materialQuantity":result,"inventoryQuantity":outResult,"materialId":materialId}
 	    	$.post("${ctx}/material/outbound/saveQuantity",params,function(result){
 	    		window.parent.frames[parentIndex].requestDetails();
 	    		closeWin();
 	    	},'json');
 	    	
	}
 	function closeThisWin() {
 		
		closeWin();
	}
 	function checkQuantity(t){
 		var inputQuantity = $(t).val();
 		if (inputQuantity==""||inputQuantity==null) {
 			inputQuantity = 0;
		}else{
 		    inputQuantity = parseFloat(inputQuantity.replace(/,/g,""));
		}
    	var thisTR = t.parentNode.parentNode;
    	var materialQuantity = parseFloat(($(thisTR).find(".mQuantity").val()).replace(/,/g,""));
    	if(materialQuantity<inputQuantity){
    		//tipParent("<spring:message code="outbound_requestex_check_quantity_msg"/>");
    		$(t).css("color","red");
    		return false;
    	}else{
    		$(t).css("color","");
    	}
    }
 	
 	function quantityFun(t){
 		var inputQuantity = $(t).val();
 		if (inputQuantity==""||inputQuantity==null) {
 			inputQuantity = 0;
		}else{
 		    inputQuantity = parseFloat(inputQuantity.replace(/,/g,""));
		}
    	var thisTR = t.parentNode.parentNode;
    	var materialQuantity = parseFloat(($(thisTR).find(".mQuantity").val()).replace(/,/g,""));
    	var subQuantity = materialQuantity - inputQuantity;
    	$(thisTR).find(".materialQuantity").html(subQuantity);
 	}
 	/* 保存创建/编辑信息 */
    function saveForm(){
 		/* 验证  */
    	var length = $("input.inputQuantity").length;
 		var result = parseFloat(0);
 		for (var i = 0; i < length; i++) {
 			var inventoryQuantity = $(".inputQuantity")[i].value;
 			var materialQuantity = $(".mQuantity")[i].value;
 			if (inventoryQuantity==null||inventoryQuantity=="") {
 				inventoryQuantity = "0";
			}
 			if (materialQuantity==null||materialQuantity=="") {
 				materialQuantity = "0";
			}
 			inventoryQuantity = inventoryQuantity.replace(/,/g,"");
 			materialQuantity = materialQuantity.replace(/,/g,"");
 			if (parseFloat(materialQuantity)<parseFloat(inventoryQuantity)) {
 				tipParent("<spring:message code="outbound_requestex_check_quantity_msg"/>");
 				return;
			}
		}
    	formUnFormat($("#inputForm"));
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/material/outbound/save",params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result.message);
    		saveQuantity();
    	},'json');
    	
    }
    </script>
    <style type="text/css">
    		.tab-kcmxno{width: 50px;}
		    .tab-kcmxckmc{width: 140px;}
		    .tab-kcmxhjwz{width: 140px;}
		    .tab-kcmxkcsl{width: 140px;}
		    .tab-kcmxbz{width: 140px;}
    </style>
</head>
<body style="min-width: 770px">
<form id="inputForm">
<div class="layerHeader clearfix" style="width: 800px">
	<p class="headerTitle"><spring:message code="outbound_detail_outboundDetails"/></p>
	<div class="headerButton clearfix">
	<c:if test="${materialOutInbound.inventoryStatus!=inventoryStatusAll}">
		<c:if test="${materialOutInbound.requestQuantity != null && materialOutInbound.requestQuantity != '' }">
			<button type="button" onclick="saveForm();"><spring:message code="common_save" /></button>
		</c:if>
	</c:if>
       <button type="button" onclick="closeThisWin();"><spring:message code="outbound_detail_set_close" /></button>
     </div>
</div>
<div class="listArea" style="width: 800px">
<input type="hidden" name="id" value="${materialOutInbound.id}"/>
<input type="hidden" name="materialId" value="${materialOutInbound.materialId}"/>
<input type="hidden" name="inventoryDetailId" value="${materialOutInbound.inventoryDetailId}"/>
<input type="hidden" name="inventoryCategory" value="${materialOutInbound.inventoryCategory}"/>
                <div class="items clearfix" style="margin-left: 10px;">
                <div class="col-33 clearfix haveToBox">
                        <p class="tit"><spring:message code="outbound_detail_set_materialCode"/></p>
                        <label>${materialOutInbound.materialCode }</label>
                    </div>
                    <div class="col-33 clearfix haveToBox">
                   		<p class="tit"><spring:message code="outbound_detail_set_materialName"/></p>
                        <label>${materialOutInbound.materialNameCn }</label> 
                	</div>
            </div>
	<div style="height: 20px;padding: 0 10px;">
   		<p class="tit"><spring:message code="outbound_detail_set_inventoryDetail"/></p>
   	</div>
        <div class="tableArea tabBoxSm" >
            <div class="tableScrollSm tabSm" style="overflow: auto;height: 400px;width:774px">
                <table cellpadding="0" class="tableHead " >
                    <thead>
                    <tr>
                        <th><p class="tab-kcmxno"><spring:message code="common_no"/></p></th>
		                <th><p class="tab-kcmxckmc"><spring:message code="outbound_detail_set_warehouseName"/></p></th>
		                <th><p class="tab-kcmxhjwz"><spring:message code="outbound_detail_set_rackPlace"/></p></th>
		                <th><p class="tab-kcmxkcsl"><spring:message code="outbound_detail_set_materialQuantity"/></p></th>
		                <th><p class="tab-kcmxkcsl"><spring:message code="outbound_detail_set_inventoryQuantity"/></p></th>
		                <th><p class="tab-kcmxbz"><spring:message code="outbound_detail_set_remarks"/></p></th>
                    </tr>
                    </thead>
                </table>
                <table cellpadding="0" class="tableBody" >              
                    <tbody id = "listHtml">
                    <c:if test="${not empty materialOutInbound.requestDetailsList}">
            			<c:forEach items="${materialOutInbound.requestDetailsList}" var="requestDetailsInfo" varStatus="status">
            			<tr>
                			<td><p class="tab-kcmxno">${status.count}</p></td>
                			<td><p class="tab-kcmxckmc">${requestDetailsInfo.warehouseName}</p></td>
                			<td><p class="tab-kcmxhjwz">${requestDetailsInfo.rackPlace}</p></td>
                			<td><p class="tab-kcmxkcsl materialQuantity"><fmt:formatNumber value="${requestDetailsInfo.materialQuantity-requestDetailsInfo.realQuantity}" pattern="#,##0.00#"/></p></td>
                			<td class="tab-kcmxkcsl"><input type="tel" class="inputQuantity" name="requestDetailsList[${status.index }].inventoryQuantity" style="width: 140px;" value="<fmt:formatNumber value="${requestDetailsInfo.inventoryQuantity}" pattern="#,##0.00#"/>" onblur="formatNumber(this);checkQuantity(this);" onfocus="unFormat(this)" onchange="quantityFun(this);"/></td>
                			<td><p class="tab-kcmxbz">${requestDetailsInfo.remarks}</p></td>
                			<input type="hidden" name="requestDetailsList[${status.index }].warehouseID" value="${requestDetailsInfo.warehouseID}"/>
                			<input type="hidden" name="requestDetailsList[${status.index }].rackID" value="${requestDetailsInfo.rackID}"/>
                			<input type="hidden" name="requestDetailsList[${status.index }].id" value="${materialOutInbound.id}"/>
                			<input type="hidden" name="requestDetailsList[${status.index }].inventoryDetailId" value="${materialOutInbound.inventoryDetailId}"/>
                			<input type="hidden" class="mQuantity" value="<fmt:formatNumber value="${requestDetailsInfo.materialQuantity-requestDetailsInfo.realQuantity+requestDetailsInfo.inventoryQuantity}" pattern="#,##0.00#"/>"/>
            			</tr>
            			</c:forEach>
            		</c:if>
                    </tbody>
                </table>
            </div>
            
    </div>
    <div id = "paging" ></div>
</div>
</form>
<script type="text/javascript">

</script> 
</body>
</html>
	